<HTML>
<HEAD>
<TITLE>xFunctions Educational Mathematics Applet -- Using Examples</TITLE>
</HEAD>
<BODY bgcolor="#FFFFCC">

<br><br>
<H1 align=center><font color="#990000">xFunctions: Using Examples</font></H1>
<br>

<blockquote>

<p><font size="+1" color="#990000">xFunctions</font> is an educational applet
for exploring several aspects of calculus and precalculus mathematics.
Its use is fully described on the <a href="index.html">main xFunctions Web page</a>.
This page, on the other hand, explains how extra functions and examples can be added to xFunctions.
The examples can be specified as applet parameters in the HTML source code of
a Web page.  If xFunctions is run as a standalone applications, it can read
examples from a file that is specified as a command line parameter.
Unfortunately, if you want to create such examples, you have to
encode them by hand.  This page explains how to do the encoding.</p>

<p>There are two versions of the applet, one that appears right on the Web
page and one that can be launched in a separate window.  Examples are used
in the same way with either version of the applet.  You can see them in the
"Launcher" version of the applet on the <a href="index.html">main page</a>.
The xFunctionsLauncher applet on that page is
specified with the following rather long applet tag, which encodes three example
functions and eight examples for the various xFunctions utilities:</p>

<pre>
   &lt;applet  archive=&quot;xFunctions.zip&quot;  code=&quot;xFunctionsLauncher.class&quot;  width=200 height=30&gt;
      &lt;param  name=&quot;1&quot;   value=&quot;function; -5,5,-5,5; table; Tbl; 3; -5,-2; -3,1; -1,3; 0,0; 2,1; 4,2; 5,1&quot;&gt;
      &lt;param  name=&quot;2&quot;   value=&quot;function; -5,5,-5,5; graph; B; -5,1,-1, -3,-0.5,1; -3,-0.5,-1, 0,2,0; 0,-2,4, 2.5,1,-1; 2.5,1,-1, 5,0,1&quot;&gt;
      &lt;param  name=&quot;3&quot;   value=&quot;function; 0,5,-1,4; expression; Split;&quot;&gt;
      &lt;param  name=&quot;4&quot;   value=&quot;+  x^2; x &lt; 1; 2*x - 1; x &gt;= 1 and x &lt; 2; 5 - x; x &gt;= 2 and x &lt; 3; (x-3)^2 + 1&quot;&gt;
      &lt;param  name=&quot;5&quot;   value=&quot;multigraph; tan(x) = sin(x) / cos(x); -5,5,-5,5; tan(x); sin(x); cos(x)&quot;&gt;
      &lt;param  name=&quot;6&quot;   value=&quot;animation; Tweening Animation; -8,8,-2,2,0,1,50; sin(x)*k + (1/(x^2+1))*(1-k); false&quot;&gt;
      &lt;param  name=&quot;7&quot;   value=&quot;param; Squiggly Curve; -6,6,-6,6,0,6.3,300; 2*cos(5*t) + 3*cos(9*t); 2*sin(10*t) - 4*sin(2*t)&quot;&gt;
      &lt;param  name=&quot;8&quot;   value=&quot;derivatives; Bezier Curve Derivative; -5,5,-5,5; b(x)&quot;&gt;
      &lt;param  name=&quot;9&quot;   value=&quot;reimann; Close to e; 1,2.718,0,1.5,10; 1/x; 3&quot;&gt;
      &lt;param  name=&quot;10&quot;  value=&quot;graph3d; Singularity; -2,2,-2,2,-2,2,20; 1/(x^2 + y^2); 2&quot;&gt;
      &lt;param  name=&quot;11&quot;  value=&quot;g; 3D Graph with Table Function; -5,5, -5,5, -5,10, 32; Tbl(x)*Tbl(y); 4&quot;&gt;
      &lt;param  name=&quot;12&quot;  value=&quot;integral curves; Attracting/Repelling; -1.5,1.5,-1.5,1.5,0,1,0.01; x^2 + y^2 - 1; (x-y) * (x+y); 3; true;&quot;&gt;
      &lt;param  name=&quot;13&quot;  value=&quot;+   -1.2,-1.2; -0.8,,-1.2; -0.4,,-1.2;  0,,-1.2;  .4,,-1.2;  .8,,-1.2;  1.2,-1.2,;&quot;&gt;
      &lt;param  name=&quot;14&quot;  value=&quot;+   -1.2,-0.8; -0.8,-0.8; -0.4,-0.8;  0,-0.8;  .4,-0.8;  .8,-0.8;  1.2,-0.8;&quot;&gt;
      &lt;param  name=&quot;15&quot;  value=&quot;+   -1.2,-0.4; -0.8,-0.4; -0.4,-0.4;  0,-0.4;  .4,-0.4;  .8,-0.4;  1.2,-0.4;&quot;&gt;
      &lt;param  name=&quot;16&quot;  value=&quot;+   -1.2,0; -0.8,0; -0.4,0;  0,0;  .4,0;  .8,0;  1.2,0;&quot;&gt;
      &lt;param  name=&quot;17&quot;  value=&quot;+   -1.2,.4; -0.8,.4; -0.4,.4;  0,.4;  .4,.4;  .8,.4;  1.2,.4;&quot;&gt;
      &lt;param  name=&quot;18&quot;  value=&quot;+   -1.2,.8; -0.8,.8; -0.4,.8;  0,.8;  .4,.8;  .8,.8;  1.2,.8;&quot;&gt;
      &lt;param  name=&quot;19&quot;  value=&quot;+   -1.2,1.2; -0.8,1.2; -0.4,1.2;  0,1.2;  .4,1.2;  .8,1.2;  1.2,1.2&quot;&gt;
   &lt;/applet&gt;

</pre>

<hr>

<br><h2><font color="#990000">Applet Params and Files</font></h2>

<p>An applet parameter is specified by a &lt;param&gt; tag between the opening &lt;applet&gt;
tag and the closing &lt;/applet&gt;.  The applet can read these parameters when it runs.
A &lt;param&gt; tag has the form

<pre>              &lt;param  name="<font color=blue>some name</font>"  value="<font color=blue>some value</font>"&gt;
</pre>

<p>For the xFuctions applet, the names must be the consecutive numbers 1, 2, 3, 4, ...
You can have as many as you want, but you can't skip any.  The applet will stop reading
as soon as it encounters a missing number.  (By the way, the applet requests params by
name, and it doesn't matter to the applet what order the params appear in the
&lt;applet&gt; tag.  That's why you need the names.)</p>

<p>When xFunctions processes these parameters, it will simply process all the param values
in order, as if they were lines in a file.  In fact, if you run xFunctions as a standalone
application, you can put the exact same lines in a file and tell xFunctions to read them
when it starts up.  (You do this by providing the file name as a command line argument
when you run xFunctions. If you download xFunctions, using one of the downloading links
on the <a href="index.html">main xFunctions page</a>, you'll find a 
<a href="README.txt">README</a> file that explains more about running xFunctions as
an application.  You also find a <a href="example_file.txt">file of examples</a>
which contains the same examples given in the applet tag above.)</p>

<p>Now, when xFunctions reads the examples, either from applet params or from a file,
<b>any line beginning with a plus sign (+) is appended to the preceding line</b>.  (The plus
sign is discarded.)  This allows you to spread long example definitions over several
lines.  After lines have been joined in this way, each line defines one example.</p>

<p>So, all you need to know is how to compose a line to specify each of the possible types of example.
It's not all that complicated, but the computer is picky about the syntax, and it's easy to
make mistakes.  If an example contains an error, xFunctions will ignore the example.  (It won't crash.)
To help you find the problem, xFunctions writes messages to standard output as it processes
the example descriptions.  If it finds an error, it prints an error message.  If you run
xFunctions in a Web browser, you will have to figure out where it actually prints these
messages.  Netscape, for example, prints them to a "Java Console."  You can open this
console with an entry under the "Communicator" menu (possibly inside a "Tools" submenu
in this menu, depending on what version of the program you are using).</p>

<p>(Note: As an alternative to -- or in addition to -- using applet params to specify
examples in an applet, you can put the examples in a file and tell the applet to read
that file.  The file should be on the Web server in the same directory with the
source file of the Web page.  Then you just have to
give the applet the name of the file as an applet parameter.  The name is specified
in a &lt;param&gt; tag whose name is "file" and whose value is the name of the file.
For example: <tt>&lt;param&nbsp;name="file"&nbsp;value="example_file.txt"&gt;</tt>.)</p>

<p>Every example specification consists of a series of items separated by
semicolons (;).  The first item tells what kind of example it is.  This can 
be the word "function" to specify that you are defining a new function, or it can be
the name of a utility (Multigraph, Animate,...) to specify that you are giving an
example for one of the utilities.  Actually, <b>xFunctions only looks at the first
character</b>, so you can say "f" or "func" or "fried green tomatoes" instead of
"function".  Also, you can use either upper or lower case.  The rest of the items
in the example depend on which type of example it is.  I'll give lists of the
items required for all the different types of examples.</p>

<br><hR>

<br><h2><font color="#990000">Defining New Functions in Examples</font></h2>

<p>It is possible to define new functions as examples.  These will be added to the list of
functions that appears on xFunction's main screen.  Once they are in that list, they can
be used in the Utilities and in the definitions of other functions -- you can even use them
in later examples.  There are three ways to define functions:  as one or more expressions,
as a graph, or as a table of xy-points.  I'll describe each of these possibilities
separately, but all three types of function specification begin with the same
four items (separated by semicolons):  the word "function" (or any string beginning with
an "f"), the xy-limits for the function, the type of function, and the name of the function.</p>

<p>The <b>xy-limits</b> consist of four numbers, separated by commas.  These are the xmin, xmax,
ymin, and ymax values that will be used in the corresponding input boxes when the function
is graphed on the Main Screen.  Note that they are not the domain and range of the function.
They merely specify what region of the xy-plane is displayed on the Main Screen by default.
The <b>type</b> of function is one of the words "expression", "table", or "graph".
Again, xFunctions will actually only look at the first character, so you can abbreviate
these to "e", "t", and "g".  The <b>name</b> of the function can be any sequence of
letters and digits, as long as it begins with a letter.  You cannot redefine a function
that is already defined.  The letters can be either upper or lower case.  (When names are
used in expressions, xFunctions doesn't distinguish between upper and lower case.
However, when it places functions in the list on the Main Screen, it will order
upper case letters before lower case letters.  You can make the functions that you define
easier to find if you start their names with upper case letters, so that they appear
at the top of the list.)</p>


<br><h3><font color="#990000">Expression Functions</font></h3>

<p>An expression function is defined by from one to eight expressions.  These are the same
expressions that would be entered in the Expression Function Input Screen in xFunctions.
Note that if you have more than one expression, then every even-numbered expression
must be a logical-valued expression (such as "x&nbsp;&lt;=&nbsp;3") which defines the
domain on which the previous expression is valid.  For an expression function example,
the defining expressions are simply listed as separate items in the example -- separated
by semicolons -- after the four standard items.  Here is list of the items that
go into an expression function example:</p>

<OL>
<LI>the word "function" (or anything beginning with f)
<LI>a list of four numbers, separated by commas, giving the xy-limits for the display on the Main Screen
<LI>the word "expression" (or anything beginning with e)
<LI>the name of the function you are defining
<LI>anywhere from one to eight expressions that define the function (separated by more semicolons)
</OL>

<p>For example, here is how you could define the hyperbolic functions and add them to the function list
one the Main Screen.  Once they are there, they can be used just like the built-in functions.
(Note that spaces between items or between numbers in a list are not significant.)</p>

<pre>             f; -3,3,-3,3; e; sinh; (e^x - e^(-x)) / 2
             f; -3,3,-3,3; e; cosh; (e^x + e^(-x)) / 2
             f; -3,3,-3,3; e; tanh; sinh(x) / cosh(x)
</pre>


<br><h3><font color="#990000">Table Functions</font></h3>

<p>A table function is defined by a list of xy-points that lie on the graph of the function.
You also have to specify how to fill in the graph between points.  There are three possible
styles: a step function, a piecewise linear function, or a smooth function.
In an example, the style is specified (in order of increasing "quality") as one of the
numbers 1, 2, or 3.  The specification for a table function includes the following items:</p>

<OL>
<LI>the word "function" (or anything beginning with f)
<LI>a list of four numbers, separated by commas, giving the xy-limits for the display on the Main Screen
<LI>the word "table" (or anything beginning with t)
<LI>the name of the function you are defining
<LI>one of the numbers 1, 2, or 3 to specify whether its a step function, piecewise linear, or smooth
<LI>two or more points, where each point is a pair of numbers separated by a comma.  The 
x-values of the points must be in strictly increasing order.  The points are separated by semicolons.
</OL>

<p>For example, this defines a piecewise linear function named "W" that looks like a W"</p>

<pre>              f; -5,5,0,5; t; W; 2; -4,4; -2,0; 0,2; 2,0; 4,4
</pre>


<br><h3><font color="#990000">Graph Functions</font></h3>

<p>A graph function is a sequence of Bezier segments.  Each segment is defined by
a list of six numbers, separated by commas.  The numbers give:</p>

<UL>
<LI>the x-coordinate of the left endpoint
<LI>the y-coordinate of the left endpoint
<LI>the slope of the graph at the left endpoint
<LI>the x-coordinate of the right endpoint
<LI>the y-coordinate of the right endpoint
<LI>the slope of the graph at the right endpoint
</UL>

<p>The x-coordinates in a segment must agree with the x-coordinates of its neighbors.
(It is not possible to define graphs with gaps in the domain.)  The y-coordinates
don't have to agree, so you can make functions with discontinuities.  Even if the
y-coordinates of neighboring segments do agree, the slopes don't have to
agree, so you can make functions with corners.</p>

<p>The specification of a graph function consists of the following items:

<OL>
<LI>the word "function" (or anything beginning with f)
<LI>a list of four numbers, separated by commas, giving the xy-limits for the display on the Main Screen
<LI>the word "graph" (or anything beginning with g)
<LI>the name of the function you are defining
<LI>specifications for one or more bezier segments, separated by semicolons.  Each segment is
specified as a list of six numbers, as described above, separated by commas.
</OL>

<p>Here is an example that defines a graph function named "Grf" consisting of two bezier segments with a
sharp corner at the point (0,0) and with horizontal tangents at (-2,1) and (2,1)</p>

<pre>            f; -2,2,0,2; g; Grf; -2,1,0, 0,0,-5; 0,0,5, 2,1,0;</pre>


<br><hr>

<br><h2><font color="#990000">Examples for the Utilities</font></h2>

<p>To define an example for one of the seven utilities, you have to say what goes into
each of the inputs on that utility screen.  In all cases, this includes a set of values
for xmin, xmax, ymin, ymax, and possibly for other numerical values.  It also includes
one or more expressions to define the functions that the utility will use.  There might
be other inputs, such as the checkbox labeled "Loop back and forth" in the Animate Utility
or the radio buttons for controlling the style of graph in the Graph 3D Utility.
I'll describe the exact format you need in order to specify the inputs for each of the
utilities.  In all cases, the first item in the example is the name of the utility,
which can be abbreviated to as little as one letter.  This is followed by a menu entry,
which is the string that will appear in the pop-up menu in xFunctions to describe this
example to the user.  (It has to be short enough to fit into this menu.)
Next comes a list of numbers, separated by commas, that go into the
numerical input boxes in the utility.
This is followed by one or more expressions, separated by semicolons.  Any further
inputs are specified after that.</p>


<br><h3><font color="#990000">Multigraph Utility</font></h3>

<p>An example for the multigraph utility is specified by</p>

<OL>
<LI>the word "multigraph" (or anything beginning with m)
<LI>the menu entry for the example, which can be any (short) string
<LI>a list of 4 numbers, separated by commas, specifying xmin, xmax, ymin, and ymax
<LI>anywhere from one to eight expressions, giving the functions of x that are to be
graphed, separated by more semicolons.
</OL>

<p>For example:</p>

<pre>                m; An interesting function; -1,2,0,2; abs(x)^x
                multigraph; Two halves of a circle; -2,2,-2,2; sqrt(1-x^2); -sqrt(1-x^2)
</pre>
       

<br><h3><font color="#990000">Animate Utility</font></h3>

<p>For the animate utility, the list of numbers has seven entries.  In addition to 
xmin, xmax, ymin, and ymax, there are kmin and kmax, which give the limits on the parameter
k, and the number of intervals in the
animation.  The number of intervals must be between 1 and 1000, inclusive.
The expression to be animated uses the variables x and k.  There is a final item
that specifies whether the "Loop back and forth" checkbox should be on.
The value of this item must be specified as "true" or "false".  (As usual, you can
abbreviate to one character.)  When the user selects an animation example, the
animation will start playing automatically after a second or two.  So, an Animate
Utility example consists of:</p>

<OL>
<LI>the word "animate" (or anything beginning with a)
<LI>the menu entry for the example, which can be any (short) string
<LI>a list of 7 numbers, separated by commas, specifying xmin, xmax, ymin, ymax, kmin, kmax
    and the number of intervals, where the number of intervals is between 1 and 1000
<LI>an expression that uses the variables x and k
<LI>one of the values "true" or "false" to specify whether the animation loops back and forth
</OL>

<p>For example:</p>

<pre>            a; Functions Converging to f(x)=x; 0,1.2,0,1.2,0,50,50; x^k; false
</pre> 


<br><h3><font color="#990000">Parametric Curves Utility</font></h3>

<p>The Parametric Curves Utility requires seven numerical inputs.  The three extra inputs
are the values of tmin and tmax (the range of values for the parameter) and the
number of points that are plotted on a curve.  The number of points must be between
2 and 1000, inclusive.  You can have up to eight curves.  For each two curves,
you need <b>two</b> expressions involving the variable t, one to define
x(t) and one to define y(t).  A Parametric Curves example consists of:</p>

<OL>
<LI>the words "parametric curves" (or anything beginning with p)
<LI>the menu entry for the example, which can be any (short) string
<LI>a list of 7 numbers, separated by commas, specifying xmin, xmax, ymin, ymax, tmin, tmax,
and the number of points on a curve.  The number of points must be between 2 and 1000.
<LI>an even number of expressions, from two to sixteen, 
giving the functions of t that define x(t) and y(t) for each curve, separated by more semicolons.
</OL>

<p>For example (using a + on the second line to break the example into two lines):</p>

<pre>              p; A Circle and Two Ellipses; -3,3, -3,3, 0,6.29, 200; 2*cos(t); 2*sin(t);
              +   2*cos(t); sin(t);   cos(t); 2*sin(t)
</pre>


<br><h3><font color="#990000">Derivatives Utility</font></h3>

<p>An example for the derivatives Utility consists of the following items:</p>

<OL>
<LI>the word "derivatives" (or anything beginning with d)
<LI>the menu entry for the example, which can be any (short) string
<LI>a list of 4 numbers, separated by commas, specifying xmin, xmax, ymin, and ymax
<LI>an expression giving the function of x
</OL>

<p>For example:</p>

<pre>             d; Vertical tangent at x=0?; -2,2,-2,2; abs(x)^x
</pre>


<br><h3><font color="#990000">Riemann Sums Utility</font></h3>

<p>The Riemann Sums Utility requires five numerical inputs.  The last one is the number of
intervals into which the domain is to be divided.  This must be a number between 1 and 512,
inclusive.  You also have to specify which summation method will be displayed on the
graph.  There are six possible methods, which are specified by the numbers from 1 to 6:
left endpoint rule, right endpoint rule, midpoint rule, inscribed rectangle rule,
circumscribed rectangle rule, and trapezoid rule.  So, an example consists of:</p>

<OL>
<LI>the words "riemann sums" (or anything beginning with r)
<LI>the menu entry for the example, which can be any (short) string
<LI>a list of 5 numbers, separated by commas, specifying xmin, xmax, ymin, ymax, and
the number of subintervals.  The number of subintervals must be between 1 and 512.
<LI>An expression giving the function of x
<LI>A number from 1 to 6 specifying the display method
</OL>

<p>For example:</p>

<pre>         r; Area Under a Parabola; 0,1,-0.2,1.2,6; x^2; 3
</pre>


<br><h3><font color="#990000">Integral Curves Utility</font></h3>

<p>An Integral Curves example requires seven numbers.  The fifth and sixth of these
go in the boxes labeled "Start x" and "Start y" in the utility.  (These values give
a point where a curve will start when the user presses the New Curve button.
You might not find it useful to provide such a point in an example, but you have
to include it anyway.)  The seventh number is the "dt" value that specifies time
between points on the curves.  The example must also specify the integration
method as a number 1, 2, or 3 standing for Euler's method, Runge-Kutta Order 2,
or Runge-Kutta Order 4 (in order of increasing "quality").
Finally, you have to specify whether the checkbox labeled "Extend curves
in both directions" is checked.  You do this with one of the values
"true" or "false", which can be abbreviated to just "t" or "f".</p>

<p>The Integral Curve utility draws integral curves starting at specified points.
You can, optionally, include a list of points in your example where curves
are to be started.  Each point is specified as a pair of numbers, separated by 
a comma.  If your example includes such points, then the curves will be started
a second or two after the user chooses the example from the menu.</p>

<p>An Integral Curve example consists of</p>

<OL>
<LI>the words "integral curves" (or anything beginning with i)
<LI>the menu entry for the example, which can be any (short) string
<LI>a list of 7 numbers, separated by commas, specifying xmin, xmax, ymin, ymax,
Start x, Start y, and dt.  The value of dt must be greater than zero.
<LI>two expressions using the variables x and y, separated by a semicolon.
These give the values of dx/dt and dy/dt.
<LI>A number 1, 2, or 3 specifying the integration method.
<LI>One of the values "true" or "false" to specify whether curves are to be
drawn both forwards and backwards in time
<LI>Optionally, you can add any number of points.  Each point is a pair of
numbers, separated by a comma.  The points are separated by semicolons.
</OL>

<p>Here is an example that does not use extra points.  For an example with
points, see the example in the applet tag at the top of this page.</p>

<pre>            i; Pendulum Phase Space; -4, 4, -4, 4, 0, 0, 0.1; y; sin(x); 3
</pre>


<br><h3><font color="#990000">Graph 3D Utility</font></h3>

<p>For the Graph 3D Utility, you need seven numbers, including zmin, zmax, and the
grid size.  The grid size is a number between 8 and 64, inclusive, that determines 
how many points are plotted on the graph.  Then, in addition to a function of x and y,
you need to specify which type of graph will be drawn.  There are four types,
which are specified by the numbers 1, 2, 3, and 4 (in order of increasing "quality"):
wireframe model, wireframe with hidden lines removed, shaded model, and shaded model
with wires.  So, an example for Graph 3D consists of:</p>

<OL>
<LI>the words "graph 3d" (or anything beginning with g)
<LI>the menu entry for the example, which can be any (short) string
<LI>a list of 7 numbers, separated by commas, specifying xmin, xmax, ymin, ymax,
zmin, zmax, and the grid size.  The grid size must be between 8 and 64.
<LI>an expression giving the function of x and y that is to be graphed
<LI>A number between 1 and 4 specifying the style of graph.
</OL>

<p>For example:</p>

<pre>                g; Eggcrate; -4,4,-4,4,-2,2,50; sin(x)*cos(y); 4
</pre>



<br><hR>
<center><font size="-1"><a href="http://math.hws.edu/eck/index.html">David Eck</a>
(<a href="mailto:eck@hws.edu">eck@hws.edu</a>), 27 October 1999</font></center>

</blockquote>

</BODY>
</HTML>

